Crate zenoh

source ·
Expand description

Zenoh /zeno/ is a stack that unifies data in motion, data at rest and computations. It elegantly blends traditional pub/sub with geo distributed storage, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.

Before delving into the examples, we need to introduce few Zenoh concepts. First off, in Zenoh you will deal with Resources, where a resource is made up of a key and a value. The other concept you’ll have to familiarize yourself with are key expressions, such as robot/sensor/temp, robot/sensor/*, robot/**, etc. As you can gather, the above key expression denotes set of keys, while the * and ** are wildcards representing respectively (1) an arbitrary string of characters, with the exclusion of the / separator, and (2) an arbitrary sequence of characters including separators.

Below are some examples that highlight these key concepts and show how easy it is to get started with.

Examples

Publishing Data

The example below shows how to produce a value for a key expression.

use zenoh::prelude::r#async::*;

#[async_std::main]
async fn main() {
    let session = zenoh::open(config::default()).res().await.unwrap();
    session.put("key/expression", "value").res().await.unwrap();
    session.close().res().await.unwrap();
}

Subscribe

The example below shows how to consume values for a key expresison.

use futures::prelude::*;
use zenoh::prelude::r#async::*;

#[async_std::main]
async fn main() {
    let session = zenoh::open(config::default()).res().await.unwrap();
    let subscriber = session.declare_subscriber("key/expression").res().await.unwrap();
    while let Ok(sample) = subscriber.recv_async().await {
        println!("Received : {}", sample);
    };
}

Query

The example below shows how to make a distributed query to collect the values associated with the resources whose key match the given key expression.

use futures::prelude::*;
use zenoh::prelude::r#async::*;

#[async_std::main]
async fn main() {
    let session = zenoh::open(config::default()).res().await.unwrap();
    let replies = session.get("key/expression").res().await.unwrap();
    while let Ok(reply) = replies.recv_async().await {
        println!(">> Received {:?}", reply.sample);
    }
}

Re-exports

pub use zenoh_config as config;
pub use zenoh_buffers as buffers;

Modules

Callback handler trait.
Tools to access information about the current zenoh Session.
Key expression types and utils.
⚠️ WARNING ⚠️
A “prelude” for crates using the zenoh crate.
A map of key/value (String,String) properties.
Publishing primitives.
Query primitives.
Queryable primitives.
Sample primitives
Scouting primitives.
Selector to issue queries
Subscribing primitives.
Time related types and functions.
Value primitives.

Structs

A builder returned by open used to open a zenoh Session.
A zenoh session.

Traits

Functions to create zenoh entities with 'static lifetime.
A trait implemented by types that can be undeclared.

Functions

Open a zenoh Session.
Scout for routers and/or peers.

Type Definitions

A zenoh error.
A zenoh result.